//
// Created by Incredible on 17/3/17.
//

#ifndef BINARYSEARCHFLOORANDCEIL_SEARCHTESTHELPER_H
#define BINARYSEARCHFLOORANDCEIL_SEARCHTESTHELPER_H

#include <iostream>
#include <assert.h>

using namespace std;

namespace {

    //构造一个有n个元素的数组，其范围[l，r];
    int *generateRandomArray(int n, int l, int r) {

        srand(time(NULL));
        int * arr = new int[n];

        for (int i = 0; i < n; ++i) {
            arr[i] = rand()%(r-l+1)+l;
        }

        return arr;
    }

    //构造一个近乎有序的数组，其范围[l，r);
    int *generateNearlyRandomArray(int n, int l, int r, int swapTime) {

        srand(time(NULL));
        int * arr = new int[n];

        for (int i = l; i < r-l; ++i) {
            arr[i] = i;
        }

        for (int j = 0; j < swapTime; ++j) {
            swap(arr[rand()%(r-l+1)+l],arr[rand()%(r-l+1)+l]);
        }

        return arr;
    }

    //打印数组
    template <typename T>
    void printArray(T arr[], int n){
        assert(n>0);

        for (int i = 0; i < n; ++i) {
            cout<<arr[i]<<" ";
        }
        cout<<endl;
    }


};

#endif //BINARYSEARCHFLOORANDCEIL_SEARCHTESTHELPER_H
